#include"Siruri.h"
Siruri::Siruri(void)
{
    dimens=1;
    p=new char[dimens];
    if(!p)
     {
         cout<<"Eroare la alocare!"<<endl;
         exit(1);
     }
     *p='\0';
}
Siruri::Siruri(char *sir)
{
    dimens=strlen(sir) +1;
    p=new char[dimens];
    if(!p)
    {
        cout<<"Eroare la alocare"<<endl;
        exit(1);
    }
    strcpy(p,sir);
}
Siruri::Siruri(const Siruri &obiect)
{
    dimens=obiect.dimens;
    p=new char[dimens];
    if(!p)
    {
        cout<<"Eroare la alocare"<<endl;
        exit(1);
    }
    strcpy(p,obiect.p);
}
ostream &operator<<(ostream &flux, Siruri &obiect)
{
    flux<<obiect.p;
    return flux;
}

Siruri Siruri::operator+(Siruri &obiect)
{
    int lungime;
    Siruri temp;
    delete temp.p;
    lungime=strlen(obiect.p) + strlen(p) +1;
    temp.p=new char[lungime];
    temp.dimens = lungime;
    if(!temp.p)
    {
        cout<<"Eroare la alocare"<<endl;
        exit(1);
    }
    strcpy(temp.p, this->p);
    strcat(temp.p, obiect.p);
    return temp;
}
Siruri Siruri::operator+(char *s)
{
    int lungime;
    Siruri temp;

    delete temp.p;
    lungime=strlen(s)+strlen(p)+1;
    temp.p=new char[lungime];
    temp.dimens=lungime;
    if(!temp.p)
    {
        cout<<"Eroare la alocare"<<endl;
        exit(1);
    }
    strcpy(temp.p, this->p);
    strcat(temp.p,s);
    return temp;
}

Siruri operator+(char *s, Siruri &obiect)
{
    int lungime;
    Siruri temp;
    delete temp.p;
    lungime = strlen(s)+strlen(s) +1;
    temp.p=new char[lungime];
    temp.dimens=lungime;
    if(!temp.p)
    {
        cout<<"Eroare la alocare";
        exit(1);
    }
    strcpy(temp.p,s);
    strcat(temp.p, obiect.p);
    return temp;
}

